%{
    This file is part of StemCellQC, a video bioinformatics software
    toolkit for analysis of phase contrast microscopy videos.
    Copyright 2013-2015 Vincent On. [vincenton001-at-gmail.com]

    StemCellQC is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as 
    published by the Free Software Foundation, either version 3 of the 
    License, or (at your option) any later version.

    StemCellQC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with StemCellQC.  If not, see <http://www.gnu.org/licenses/>.
%}

function varargout = Classify_samples_gui(varargin)
% CLASSIFY_SAMPLES_GUI MATLAB code for Classify_samples_gui.fig
%      CLASSIFY_SAMPLES_GUI, by itself, creates a new CLASSIFY_SAMPLES_GUI or raises the existing
%      singleton*.
%
%      H = CLASSIFY_SAMPLES_GUI returns the handle to a new CLASSIFY_SAMPLES_GUI or the handle to
%      the existing singleton*.
%
%      CLASSIFY_SAMPLES_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CLASSIFY_SAMPLES_GUI.M with the given input arguments.
%
%      CLASSIFY_SAMPLES_GUI('Property','Value',...) creates a new CLASSIFY_SAMPLES_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Classify_samples_gui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Classify_samples_gui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Classify_samples_gui

% Last Modified by GUIDE v2.5 14-Nov-2013 01:29:58

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Classify_samples_gui_OpeningFcn, ...
                   'gui_OutputFcn',  @Classify_samples_gui_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Classify_samples_gui is made visible.
function Classify_samples_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Classify_samples_gui (see VARARGIN)

% Choose default command line output for Classify_samples_gui


[name_file, path] = uigetfile('*.*');
file = [path name_file];
load( file );

handles.SVMStruct = SVMStruct;
handles.labels = labels;
handles.nbStruct = nbStruct;
handles.train_samples = train_samples;
handles.remove_c = remove_c;
handles.n_frames = n_frames;

handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Classify_samples_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Classify_samples_gui_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in Load_Classifier.
function Load_Classifier_Callback(hObject, eventdata, handles)
% hObject    handle to Load_Classifier (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[name_file, path] = uigetfile('*.*');
file = [path name_file];
load( file );

handles.SVMStruct = SVMStruct;
handles.labels = labels;
handles.nbStruct = nbStruct;
handles.train_samples = train_samples;
handles.remove_c = remove_c;
handles.n_frames = n_frames;

handles.output = hObject;

% Update handles structure
guidata(hObject, handles);


% --- Executes on button press in Load_Samples.
function Load_Samples_Callback(hObject, eventdata, handles)
% hObject    handle to Load_Samples (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
run_settings.SVMStruct = handles.SVMStruct;
run_settings.labels = handles.labels;
run_settings.nbStruct = handles.nbStruct;
run_settings.train_samples = handles.train_samples;
run_settings.remove_c = handles.remove_c
run_settings.n_frames = handles.n_frames;

[ list , classification ] = hESC_run_classifier( run_settings )

rownames = list;
colnames = { 'SVM' , 'KNN' , 'Naive Bayes' };

set( handles.uitable1 , 'data', classification , 'ColumnName', colnames , 'RowName' , rownames );


